 

import Model.*;

/**
 * Associate Controller
 * @author Stefan
 */
public class AssociateController {

    private static AssociateController instance = new AssociateController();
    AssociateContainer container;

    private AssociateController()
    {
        this.container = AssociateContainer.getInstance();
    }

    /**
     * Singleton
     * @return Instance of AssociateController
     */
    public static AssociateController getInstance()
    {
        return instance;
    }

    /**
     * Add new Customer
     * @param id
     * @param name
     * @param address
     * @param company
     * @param credit
     * @param discount
     * @return 2, if added successfully
     */
    public int addCustomer(String id, String name, String address, String company, double credit, double discount)
    {
        int status = 0;
        if (container.findCustomerID(id) == null)
        {
            status++;
            if (discount < 100 && discount > -1)
            {
                Customer customer = new Customer(id, name, address, company, credit, discount);
                container.addAssociate(customer);
                status++;
            }
        }
        return status;
    }

    /**
     * Add new supplier
     * @param id
     * @param name
     * @param address
     * @param company
     * @return true, if added successfully
     */
    public boolean addSupplier(String id, String name, String address, String company)
    {
        boolean added = false;
        if (container.findSupplierID(id) == null)
        {
            Supplier supplier = new Supplier(id, name, address, company);
            added = container.addAssociate(supplier);
        }
        return added;
    }

    /**
     * Add new supplier
     * @param id
     * @param name
     * @param address
     * @param company
     * @return true, if added successfully
     */
    public boolean addEmployee(String id, String name, String address, String company)
    {
        boolean added = false;
        if (container.findEmployeeID(id) == null)
        {
            Employee employee = new Employee(id, name, address, company);
            added = container.addAssociate(employee);
        }
        return added;
    }

    /**
     * Find Associate by name
     * @param name
     * @return Customer
     */
    public Customer findCustomerName(String name)
    {
        return container.findCustomerName(name);
    }

    /**
     * Find Supplier by name
     * @param name
     * @return Supplier
     */
    public Supplier findSupplierName(String name)
    {
        return container.findSupplierName(name);
    }

    public Associate findAssociateID(String id)
    {
        return container.findAssociateID(id);
    }

    /**
     * Find Customer by id
     * @param ID
     * @return Customer
     */
    public Customer findCustomerID(String ID)
    {
        return container.findCustomerID(ID);
    }

    /**
     * Find Supplier by id
     * @param ID
     * @return Supplier
     */
    public Supplier findSupplierID(String ID)
    {
        return container.findSupplierID(ID);
    }

    /**
     * Find Employee by id
     * @param ID
     * @return Employee
     */
    public Employee findEmployeeID(String ID)
    {
        return container.findEmployeeID(ID);
    }

    /**
     * Delete Customer by name
     * @param name
     * @return true, if deleted successfully
     */
    public boolean deleteCustomerName(String name)
    {
        boolean deleted = false;
        Customer cus = findCustomerName(name);
        if (cus != null)
        {
            container.deleteAssociate(cus);
            deleted = true;
        }
        return deleted;
    }

    /**
     * Delete Customer by id
     * @param id
     * @return true, if deleted successfully
     */
    public boolean deleteAssociateID(String id)
    {
        boolean deleted = false;
        Associate ass = findAssociateID(id);
        if (ass != null)
        {
            container.deleteAssociate(ass);
            deleted = true;
        }
        return deleted;
    }

    /**
     * Check if Customer ID exists
     * @param ID
     * @return true if ID exists
     */
    public boolean checkExistingCustomerID(String ID)
    {
        boolean exist = false;
        if (container.findCustomerID(ID) != null)
        {
            exist = true;
        }
        return exist;
    }

    /**
     * Check if Supplier ID exists
     * @param ID
     * @return true if ID exists
     */
    public boolean checkExistingSupplierID(String ID)
    {
        boolean exist = false;
        if (container.findSupplierID(ID) != null)
        {
            exist = true;
        }
        return exist;
    }

    /**
     * Check if Employee ID exists
     * @param ID
     * @return true if ID exists
     */
    public boolean checkExistingEmployeeID(String ID)
    {
        boolean exist = false;
        if (container.findEmployeeID(ID) != null)
        {
            exist = true;
        }
        return exist;
    }
}
